package com.ruoyi.web.controller.match;

import java.util.List;

import com.ruoyi.match.domain.dto.InsertUserDto;
import com.ruoyi.match.domain.dto.MatchUserDto;
import com.ruoyi.match.domain.vo.MatchUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.match.domain.MatchUser;
import com.ruoyi.match.service.IMatchUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户Controller
 * 
 * @author 星野漫游
 * @date 2024-06-02
 */
@Controller
@RequestMapping("/match/user")
@Api("用户接口")
public class MatchUserController extends BaseController
{
    private String prefix = "match/user";

    @Autowired
    private IMatchUserService matchUserService;

    @RequiresPermissions("match:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询用户列表
     */
    @RequiresPermissions("match:user:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询用户列表")
    public TableDataInfo list(MatchUserDto matchUser)
    {
        startPage();//1/10
        List<MatchUserVo> list = matchUserService.selectMatchUserList(matchUser);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */
    @RequiresPermissions("match:user:export")
    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出用户列表")
    public AjaxResult export(MatchUserDto matchUser)
    {
        List<MatchUserVo> list = matchUserService.selectMatchUserList(matchUser);
        ExcelUtil<MatchUserVo> util = new ExcelUtil<MatchUserVo>(MatchUserVo.class);
        return util.exportExcel(list, "用户数据");
    }

    /**
     * 新增用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户
     */
    @RequiresPermissions("match:user:add")
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation("新增保存用户")
    public AjaxResult addSave(InsertUserDto insertUserDto)
    {
        return toAjax(matchUserService.insertMatchUser(insertUserDto));
    }

    /**
     * 修改用户
     */
    @RequiresPermissions("match:user:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        MatchUser matchUser = matchUserService.selectMatchUserByUserId(userId);
        mmap.put("matchUser", matchUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("match:user:edit")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation("修改用户")
    public AjaxResult editSave(InsertUserDto insertUserDto)
    {
        return toAjax(matchUserService.updateMatchUser(insertUserDto));
    }

    /**
     * 删除用户
     */
    @RequiresPermissions("match:user:remove")
    @Log(title = "用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    @ApiOperation("删除用户数据")
    public AjaxResult remove(String ids)
    {
        return toAjax(matchUserService.deleteMatchUserByUserIds(ids));
    }


}
